﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using Microsoft.Office.Tools.Word.Extensions;
using System.Xml.Serialization;
using System.IO;
using KOPLibrary;
using KOPLibrary.AutoComplete;
using System.Windows.Forms;
using KOPLibrary.Forms;
using System.Threading;

namespace KOP
{
    public partial class AutoComplateAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            StartupForm.CheckExecute(KOPLibrary.TemplateManagement.TemplateType.Word);
            AutoComplateManager.Startup();
            Util.CheckUpdateWeekly();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            AutoComplateManager.ShutDown();
        }

        public void FillDocument(AutoComplateInfoList infolist)
        {
            object index;
            for (int i = 1; i <= Globals.AutoComplateAddIn.Application.ActiveDocument.ContentControls.Count; i++)
            {
                index = i;
                Microsoft.Office.Interop.Word.ContentControl control = Globals.AutoComplateAddIn.Application.ActiveDocument.ContentControls.get_Item(ref index);
                AutoCompleteInfo info = infolist.List.FirstOrDefault(p => p.FieldName == control.Title) as AutoCompleteInfo;
                if (info != null)
                {
                    control.DropdownListEntries.Add(info.Values[0], info.Values[0], control.DropdownListEntries.Count);
                }
            }
        }
        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
      
        }

        #endregion
    }
}
